<template>
  <div id="publicCheckList">
    <!--上部搜索条件组件-->
    <topSearch :form-inline="formInline" @toSearch="toSearch"></topSearch>
    <div class="table-conBtn">
      <el-button
        v-permission="'wh:system:courseCommentExamined:adopt'"
        type="warning"
        icon="el-icon-check"
        @click="passWork"
      >
        通过
      </el-button>
      <el-button
        v-permission="'wh:system:courseCommentExamined:noadopt'"
        type="warning"
        icon="el-icon-close"
        plain
        @click="notPass"
      >
        不通过
      </el-button>
      <freshCom @searchList="searchList"></freshCom>
      <selectColumn
        ref="selectCum"
        @setColumn="setColumns"
        :nameList="columnList"
      ></selectColumn>
    </div>
    <!--下部table-->
    <el-table
      v-loading="loading"
      :data="tableData"
      stripe
      style="width: 100%"
      @selection-change="handleSelectionChange"
      max-height="490"
      ref="table"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
        :selectable="selectAble"
      ></el-table-column>
      <el-table-column type="index" width="60" label="序号">
        <template slot-scope="scope">
          {{
            scope.$index
              | filterPage(searchParams.pageNum, searchParams.pageSize)
          }}
        </template>
      </el-table-column>
      <el-table-column
        v-if="columnSHow.avatar"
        label="头像"
        min-width="100"
        align="center"
      >
        <template slot-scope="scope">
          <listImgString :imgInfo="scope.row.topic.user.avatar"></listImgString>
        </template>
      </el-table-column>
      <el-table-column
        label="昵称"
        v-if="columnSHow.name"
        prop="topic.user.name"
        min-width="130"
      ></el-table-column>
      <el-table-column
        label="大鹏号"
        v-if="columnSHow.dpAccount"
        prop="topic.user.dpAccount"
        show-overflow-tooltip
        min-width="100"
      ></el-table-column>
      <el-table-column
        label="课程名称"
        v-if="columnSHow.courseTitle"
        prop="courseTitle"
        min-width="100"
      ></el-table-column>
      <el-table-column
        label="章节名称"
        v-if="columnSHow.curriculumTitle"
        prop="curriculumTitle"
        min-width="100"
      ></el-table-column>
      <el-table-column
        label="评论内容"
        v-if="columnSHow.content"
        prop="content"
        width="100"
        class-name="text-overflow"
      >
        <template slot-scope="scope">
          <span v-html="filterContent(scope.row)"></span>
        </template>
      </el-table-column>
      <el-table-column
        label="评论时间"
        v-if="columnSHow.createdDate"
        prop="createdDate"
        min-width="150"
      ></el-table-column>
      <el-table-column
        label="用户属性"
        v-if="columnSHow.userProperty"
        prop="userProperty"
        width="80"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.userProperty"
            class="tag-span"
            :class="scope.row.userProperty | filterClass('checkUserAttr')"
            >{{ scope.row.userProperty | filterName('checkUserAttr') }}</span
          >
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column
        label="机审时间"
        v-if="columnSHow.machineAuditTime"
        prop="machineAuditTime"
        width="150"
      ></el-table-column>
      <el-table-column
        label="机审结果"
        v-if="columnSHow.machineAuditStatus"
        prop="machineAuditStatus"
        width="100"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.machineAuditStatus"
            class="tag-span"
            :class="scope.row.machineAuditStatus | filterClass('result')"
            >{{ scope.row.machineAuditStatus | filterName('result') }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="人工审核结果"
        v-if="columnSHow.peopleAuditStatus"
        prop="peopleAuditStatus"
        width="110"
      >
        <template slot-scope="scope">
          <span
            v-if="scope.row.peopleAuditStatus"
            class="tag-span"
            :class="scope.row.peopleAuditStatus | filterClass('result')"
            >{{ scope.row.peopleAuditStatus | filterName('result') }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="审核人"
        v-if="columnSHow.auditingUser"
        show-overflow-tooltip
        prop="auditingUser.name"
        width="100"
      ></el-table-column>
      <el-table-column
        label="人工审核时间"
        v-if="columnSHow.peopleAuditTime"
        show-overflow-tooltip
        prop="peopleAuditTime"
        width="150"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.peopleAuditTime">{{
            scope.row.peopleAuditTime
          }}</span>
          <div v-else>
            -
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            v-permission="'wh:system:courseCommentExamined:comment'"
            type="text"
            @click="
              changeView(
                'wh:commentCheck:publicClassCommentCheck:commentList',
                scope.row.ext.originTopicId
              )
            "
          >
            评论列表
          </el-button>
          <el-button
            v-permission="'wh:system:courseCommentExamined:adopt'"
            v-if="scope.row.peopleAuditStatus === 3"
            type="text"
            @click="handlPassWork(scope.row.id)"
          >
            通过
          </el-button>
          <el-button
            v-permission="'wh:system:courseCommentExamined:noadopt'"
            v-if="scope.row.peopleAuditStatus === 3"
            type="text"
            @click="handlNotPassWord(scope.row.id)"
          >
            不通过
          </el-button>
          <el-button
            v-permission="'wh:system:courseCommentExamined:noadopt'"
            v-if="scope.row.peopleAuditStatus === 1"
            type="text"
            @click="handlNotPassWord(scope.row.id)"
          >
            删除
          </el-button>
          <el-button
            v-if="scope.row.peopleAuditStatus === 2"
            type="text"
            @click="showFailReason(scope.row)"
          >
            未通过理由
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-全局组件-->
    <pageCom
      :searchParams="searchParams"
      :total="total"
      @searchList="searchList"
    ></pageCom>
    <!-- 不通过理由弹窗 -->
    <del-dialog
      :del-dialog-data="delDialogData"
      @reasonDel="failRequest"
    ></del-dialog>
  </div>
</template>

<script>
import topSearch from '@component/commentCheck/publicClassCommentCheck/topSearch' // 上部搜索条件
import delDialog from '@common/delDialog' // 不通过理由弹窗
import { filterCon, getCreateTime, validateOneMonth } from '@utils/pubFunction'
import { saveScrollMixins } from '@/mixins/saveScroll'
import listImgString from '@common/listImgString' // 视图预览(返回值为字符串结构)-公共组件
import { columnMixin } from '@/mixins/columnShowHide'
import {
  getSearchList,
  passSingleRequest,
  passMultRequest,
  failMultRequestAPI
} from '@/api/commentCheck/publicCourse'
export default {
  name: 'publicClassCommentCheck',
  msg: '评论审核-公开课评论审核-列表页',
  mixins: [saveScrollMixins, columnMixin],
  components: {
    topSearch,
    delDialog,
    listImgString
  },
  data() {
    return {
      loading: true,
      total: 0,
      topicType: '',
      tableData: [], // table内容
      searchParams: {
        pageNum: 1, // 当前页数
        pageSize: 10 // 页面显示条数
      },
      formInline: {
        // 搜索条件
        peopleAuditStatus: '', // 人审结果
        machineAuditStatus: '', // 机审结果
        sort: '', // 顺序
        timeType: '', // 顺序2
        checkUserId: '', // 审核人
        searchText: '', // 查询评论内容
        startTime: '', // 开始时间
        endTime: '', // 结束时间
        createTime: [],
        userProperty: '', // 用户属性
        dpAccount: '',
        userType: 'dpAccount'
      },
      multipleSelection: [],
      delDialogData: {
        isShow: false,
        params: '',
        type: '不通过'
      },
      id: '',
      columnList: [
        { label: '头像', value: 'avatar' },
        { label: '昵称', value: 'name' },
        { label: '大鹏号', value: 'dpAccount' },
        { label: '课程名称', value: 'courseTitle' },
        { label: '章节名称', value: 'curriculumTitle' },
        { label: '评论内容', value: 'content' },
        { label: '评论时间', value: 'createdDate' },
        { label: '用户属性', value: 'userProperty' },
        { label: '机审时间', value: 'machineAuditTime' },
        { label: '机审结果', value: 'machineAuditStatus' },
        { label: '人工审核结果', value: 'peopleAuditStatus' },
        { label: '审核人', value: 'auditingUser' },
        { label: '人工审核时间', value: 'peopleAuditTime' }
      ]
    }
  },
  activated() {
    this.toTableScrollHeight()
  },
  mounted() {
    this.getCreateTime()
    this.$nextTick(() => {
      setTimeout(() => {
        this.setTableScrollHeight()
        this.$refs['selectCum'].setChoose(this.columnAry)
      }, 1000)
    })
  },
  methods: {
    /* 获取列表 */
    searchList() {
      let params = { ...this.searchParams, ...this.formInline }
      if (!params.startTime || !params.endTime) {
        this.$message.warning('时间范围不允许为空')
        return
      }
      if (!validateOneMonth(params.startTime, params.endTime)) {
        this.$message.warning('时间范围须在一个月内')
        return
      }
      this.loading = true
      delete params.createTime
      getSearchList(
        params,
        (response) => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total
        },
        (response) => {
          this.loading = false
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    selectAble(row, index) {
      if (row.peopleAuditStatus === 3) {
        return true
      } else {
        return false
      }
    },
    /* 过滤返回评论内容 */
    filterContent(item) {
      return filterCon(item)
    },
    /* table选择 */
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    /* 跳转页面 */
    changeView(name, id) {
      this.$router.push({ name, query: { id } })
    },
    /* 通过 */
    passWork(type, id = '') {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      this.$confirm(
        `确认要审核通过选中的${this.multipleSelection.length}条作品评论审核信息吗？`,
        '确定提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let ids = []
        this.multipleSelection.forEach((item) => {
          ids.push(item.id)
        })
        let params = { ids }
        passMultRequest(
          params,
          (response) => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.searchList()
          },
          (response) => {
            this.$message({
              message: response.message,
              type: 'warning'
            })
          }
        )
      })
    },
    // 通过单个
    handlPassWork(id) {
      this.$confirm('确定审核通过该条公开课评论审核信息吗？', '通过提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          passSingleRequest(
            id,
            (response) => {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.searchList()
            },
            (response) => {
              this.$message({
                message: response.message,
                type: 'warning'
              })
            }
          )
        })
        .catch(() => {})
    },
    /* 批量不通过 */
    notPass() {
      if (this.multipleSelection.length <= 0) {
        this.$message.warning('请至少选择一条数据！')
        return
      }
      let ids = []
      this.multipleSelection.forEach((item) => {
        ids.push(item.id)
      })
      this.id = ids
      this.delDialogData.isShow = true
    },
    // 不通过 删除单个
    handlNotPassWord(id) {
      this.delDialogData.isShow = true
      this.id = [id]
    },
    failRequest(reason) {
      this.failMultRequest(this.id, reason)
      this.delDialogData.isShow = false
    },
    // 不通过多个请求
    failMultRequest(ids, reason) {
      let params = { ids, reason }
      failMultRequestAPI(
        params,
        (response) => {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
        },
        (response) => {
          this.$message({
            message: response.message,
            type: 'warning'
          })
        }
      )
    },
    /* 换页 */
    changePage(page) {
      this.searchParams.pageNum = page
      this.searchList()
    },
    /* 搜索 */
    toSearch() {
      this.searchParams.pageNum = 1
      this.searchList()
    },
    /* 新增编辑后，刷新列表 */
    refresh() {},
    // 显示未通过理由
    showFailReason(row) {
      this.$alert(`${row.reason}`, '未通过理由', {
        showConfirmButton: false
      }).catch(() => {})
    },
    getCreateTime() {
      const createTime = getCreateTime()
      this.formInline.startTime = createTime[0]
      this.formInline.endTime = createTime[1]
      this.formInline.createTime = createTime
    }
  }
}
</script>

<style lang="less">
#publicCheckList {
  @import url('~@common/style/clamp.less');
}
</style>
